package com.midea.ai.air.ui.home;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.midea.ai.air.R;
import com.midea.ai.air.view.MyTitleBar;

/**
 * Created by hww on 2016/3/25.
 */
public class HomeAirSetting extends Activity implements View.OnClickListener {

    private Dialog Temperature_Dialog;
    private TextView c_tv, f_tv, cf_tv;
    private TextView actionbar_left_tv;
    private RelativeLayout RL_proof, RL_children, RL_sleep, RL_share, RL_temperature, RL_local;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_homeairsetting);

        init();
    }

    MyTitleBar myTitleBar;

    private void init() {
        myTitleBar = new MyTitleBar(this);
        myTitleBar.setActionBar_center(R.string.home_air_setting);
        myTitleBar.setActioBar_left(true, R.drawable.register_titler_left, R.string.action_bar_back);
        myTitleBar.setActionBar_right(false, 0);

        create_Temperature_Select_Dialog();
        actionbar_left_tv = (TextView) findViewById(R.id.actionbar_tv_left);
        actionbar_left_tv.setTextColor(getResources().getColor(R.color.electric_histogram));

        RL_proof = (RelativeLayout) findViewById(R.id.home_air_setting_rl_mildew_proof);
        RL_children = (RelativeLayout) findViewById(R.id.home_air_setting_rl_children);
        RL_sleep = (RelativeLayout) findViewById(R.id.home_air_setting_rl_sleep_curve);
        RL_share = (RelativeLayout) findViewById(R.id.home_air_setting_rl_share_device);
        RL_temperature = (RelativeLayout) findViewById(R.id.home_air_setting_rl_temperature);
        RL_local = (RelativeLayout) findViewById(R.id.home_air_setting_rl_local_information);
        cf_tv = (TextView) findViewById(R.id.home_air_setting_rl_temperature_cf);

        RL_proof.setOnClickListener(this);
        RL_children.setOnClickListener(this);
        RL_sleep.setOnClickListener(this);
        RL_share.setOnClickListener(this);
        RL_temperature.setOnClickListener(this);
        RL_local.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.actionbar_left_relativeLayout:
                //返回
                finish();
                break;
            case R.id.home_air_setting_rl_mildew_proof:
                //强力防霉

                break;
            case R.id.home_air_setting_rl_children:
                //儿童踢被

                break;
            case R.id.home_air_setting_rl_sleep_curve:
                //睡眠曲线
                startActivity(new Intent(HomeAirSetting.this,HomeAirSettingChildren.class));
                break;
            case R.id.home_air_setting_rl_share_device:
                //分享设备

                break;
            case R.id.home_air_setting_rl_temperature:
                //温度单位
                Temperature_Dialog.show();
                break;
            case R.id.home_air_setting_rl_local_information:
                //本机信息
                startActivity(new Intent(HomeAirSetting.this,HomeAirSettingLocalInformation.class));
                break;
            case R.id.dialog_item_temperature_c:
                //温度单位：摄氏度
                if (Temperature_Dialog != null) {
                    Temperature_Dialog.dismiss();
                }
                cf_tv.setText(R.string.home_air_setting_temperature_c);
                break;
            case R.id.dialog_item_temperature_f:
                //温度单位：华氏度
                if (Temperature_Dialog != null) {
                    Temperature_Dialog.dismiss();
                }

                cf_tv.setText(R.string.home_air_setting_temperature_f);
                break;
            default:
                break;
        }
    }


    //温度单位选择
    private void create_Temperature_Select_Dialog() {
        View view = LayoutInflater.from(HomeAirSetting.this)
                .inflate(R.layout.dialog_temperture, null);
        Temperature_Dialog = new Dialog(HomeAirSetting.this, R.style.my_activate_dialog);
        Temperature_Dialog.setCancelable(true);
        Temperature_Dialog.setCanceledOnTouchOutside(true);
        Window dialogwindow = Temperature_Dialog.getWindow();
        WindowManager.LayoutParams wmlp = dialogwindow.getAttributes();
        dialogwindow.setGravity(Gravity.BOTTOM);
        dialogwindow.setAttributes(wmlp);
        Temperature_Dialog.setContentView(view);
        c_tv = (TextView) view.findViewById(R.id.dialog_item_temperature_c);
        f_tv = (TextView) view.findViewById(R.id.dialog_item_temperature_f);
        c_tv.setOnClickListener(this);
        f_tv.setOnClickListener(this);
    }


}
